﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.UserManagement.Entities;
using Domain.UserManagement;

namespace Infrastructure.CrossCutting.Security
{
    public class CurrentUser : ICurrentUser
    {
        private static volatile CurrentUser _instance;
        private static readonly object _syncRoot = new object();
        private static Presentation.Module.Security.Model.User _thisUser;
        private static Guid _userId;

        private CurrentUser()
        {}

        public static CurrentUser Instance
        {
            get
            {
                if(_instance == null)
                {
                    lock (_syncRoot)
                    {
                        if(_instance == null)
                        {
                            _instance = new CurrentUser();
                        }
                    }
                }

                return _instance;
            }
        }

        public static void RegisterUser(Presentation.Module.Security.Model.User user)
        {
            _thisUser = user;
        }

        public Presentation.Module.Security.Model.User ThisUser
        {
            get { return _thisUser; }
            
        }
        public IList<Permission> Permissions { get; set; }

        public Guid Id { get { return _userId; }
            
        }
    }
}
